<?php
	ini_set('date.timezone','Asia/Shanghai');
	header("content-type:text/html;charset=utf-8");
	header("Access-Control-Allow-Origin: *");
   	$mysql_conf = array(
        'host'    => '127.0.0.1', 
        'db'      => 'gdgf', 
        'db_user' => 'root', 
        'db_pwd'  => 'root', 
    );
   	//接收表单传递的用户名和密码
	$name=trim($_POST['name']);

	$telphone=trim($_POST['telphone']);
	//首付成数	paymentnumber
	$paymentnumber=$_POST['paymentnumber'];
	//贷款类别	paymentform
	$paymentform=$_POST['paymentform'];
	//购房楼层 level
	$level=$_POST['level'];

	$ip = $_SERVER["REMOTE_ADDR"];

	$ctime=date("Y-m-d H:i:s",time());

	if($name||$telphone){
		if(!$name){
			echo "请填写姓名！";
			die;
		}
		if(!$telphone){
			echo "请填写电话号码！";
			die;
		}
		
	    $mysqli = @new mysqli($mysql_conf['host'],$mysql_conf['db_user'],$mysql_conf['db_pwd']);

	    if ($mysqli->connect_errno) {
	        die("could not connect to the database:\n" . $mysqli->connect_error);//诊断连接错误
	    }
	    $mysqli->query("set names 'utf8';");//编码转化
	    $select_db = $mysqli->select_db($mysql_conf['db']);
	    if (!$select_db) {
	        die("could not connect to the db:\n" .  $mysqli->error);
	    }

		$sql = "INSERT INTO user (name, telphone, paymentnumber, paymentform, level, ip, create_time)
		VALUES ('$name', '$telphone', '$paymentnumber', '$paymentform', '$level', '$ip', '$ctime')";

	}else{
		echo '输入信息为空！';
		die;
	}

	// $conn = mysqli_connect("127.0.0.1","root","root");//连接数据库
	// mysqli_select_db("thinkphp");//选择数据库名
	// mysqli_query("set names utf8");//设置编码格式集
	
	// // 检测连接
	// if ($conn->connect_error) {
	//     die("连接失败: " . $conn->connect_error);
	// } 


	// $sql = "INSERT INTO user (name, telphone, create_time)
	// VALUES ('$name', '$telphone', '$ctime')";
		    //电话号码去重
    

    $qc="SELECT COUNT(*) AS telphone FROM user WHERE telphone = '".$telphone."'";
	$result=mysqli_fetch_array($mysqli->query($qc)); 
	$count=$result['telphone'];

    // $qc ="SELECT * FROM user WHERE telphone = '".$telphone."'";
    if($count){
    	echo "该号码已提交过！请勿重复提交！";
    	die;
    }
    
	if ($mysqli->query($sql) === TRUE) {
	    echo "提交成功！";
	} else {
	    echo "Error: " . $sql . "<br/>" . $mysqli->error;
	}
	
	$mysqli->close();

	// $sqlinsert="insert into t1(username,password) values('{$name}','{$pwd}')";

?>